1866B - Battling with Numbers - CodeForces Solution


combinatorics number theory

Please click on ads to support us..

Python Code:

a=int(input())
b=list(map(int,input().split()))
c=list(map(int,input().split()))
m=int(input())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
g={}
s=k=0
l=998244353
for i in range(m):
    g[x[i]]=y[i]
for i in range(a):
    if b[i] not in g or g[b[i]]<c[i]:
        s+=1
    if b[i] in g and g[b[i]]<=c[i]:
        k+=1
if k==m:
    print((2**s)%l)
else:
    print(0)

C++ Code:

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iterator>
#include <iostream>
#include <iomanip>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <fstream>

using namespace std;

#define ll long long
#define ld long double
#define forn(i, n) for (long long i = 0; i < n; i++)
#define whole(a) a.begin(), a.end()
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)


long long mod = 998244353;

long long mult(long long a, long long b)
{
	return (((a % mod + mod) % mod) * ((b % mod + mod) % mod)) % mod;
}
long long sum(long long a, long long b)
{
	return (a + b + 3 * mod) % mod;
}
long long binpow(long long x, long long n)
{
	if (n == 0) return 1;
	if (n & 1) return mult(x, binpow(x, n - 1)) % mod;

	long long t = binpow(x, n / 2) % mod;
	return mult(t, t);
}
long long divide(long long a, long long b)
{
	return a * binpow(b, mod - 2) % mod;
}

void solve()
{
	ll n;
	cin >> n;
	vector<ll> a1(n), a2(n);
	forn(i, n)
		cin >> a1[i];
	forn(i, n)
		cin >> a2[i];

	ll m;
	cin >> m;
	vector<ll> b1(m), b2(m);
	forn(i, m)
		cin >> b1[i];
	forn(i, m)
		cin >> b2[i];

	ll k = 0;
	ll cnt = n;
	forn(i, m)
	{
		while (k < n && a1[k] != b1[i]) k++;
		if (k == n)
		{
			cout << 0;
			return;
		}

		if (a2[k] == b2[i])
			cnt--;
		else if (a2[k] < b2[i])
		{
			cout << 0;
			return;
		}

	}
	cout << binpow(2, cnt) << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);


	long long t = 1;
	//cin >> t;
	while (t--)
		solve();

	return 0;
}


Comments

Submit
0 Comments
More Questions

302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson
452A - Eevee
1647B - Madoka and the Elegant Gift
1408A - Circle Coloring
766B - Mahmoud and a Triangle
1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR
1515A - Phoenix and Gold
1515B - Phoenix and Puzzle
155A - I_love_username